<?php
namespace app\modules\adminapi\controllers;

use fate\http\Request;
use app\models\User;
use app\libs\Util;

class EdituserroleController extends \app\modules\adminapi\ForceLoginPure {

    public function run() {
        global $_G;

        $req = Request::getInstance();

        $id = $req->getParameter('id');
        $email = Util::plainText($req->getParameter('email'));
        $trueName = Util::plainText($req->getParameter('true_name'));
        $phone = Util::plainText($req->getParameter('phone'));
        $role = $req->getParameter('role');

        if(!is_numeric($id) || !is_numeric($role)) {
            $this->ajaxReturn(null, 300002);
            exit;
        }

        $data = [
            'email' => $email,
            'true_name' => $trueName,
            'phone' => $phone,
            'role' => $role
        ];
        // var_dump($data);exit;

        $model = new User();
        $ret = $model->update($id, $data);

        $this->ajaxReturn(null);
    }

}
